<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>练习1:事件处理综合应用</title>
    <script src="../../js/vue.js"></script>
</head>
<body>
    <div id="app" @keydown="handleKeydown">
        {{msg}}
        <h2>count:{{count}}</h2>
        <button @click="add">+1</button>
        <button @click="minus">-1</button>
        <button @click="reset">重置</button>
    </div>
</body>
</html>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            msg: '练习1:事件处理综合应用',
            count: 0
        },
        methods: {
            add: function () {
                this.count++
            },
            minus: function () {
                this.count--
            },
            reset: function () {
                this.count = 0
            },
            handleKeydown(event) {
            switch(event.key) {
                case '+':
                this.add();
                break;
                case '-':
                this.minus();
                break;
                case '0':
                this.reset();
                break;
                }
            }
        }
    })
</script>
</script>